/**
 * Created by yanzhenghui on 15/4/15.
 */
var mutil=require('cloud/mutil.js');
var mlog=require('cloud/mlog');
var assert=require('assert');
var muser=require('cloud/muser');
var _=require('underscore');

var AVThing = 'AVThing';

function createUser(id){
  return AV.Object.createWithoutData('_User',id);
}

function getTodayThingsByUserId(req, res) {
	var userId = req.params.userId;
	var sTime = req.params.sTime;
	var p = new AV.Promise();
	var user = createUser(userId);

	var todayQuery = new AV.Query(AVThing);
	todayQuery.equalTo('user', user);
	todayQuery.equalTo('s_time', sTime);
	
	var repeatQuery = new AV.Query(AVThing);
	repeatQuery.equalTo('user', user);
	repeatQuery.greaterThan('week_num', 0);
	
	var mainQuery = AV.Query.or(todayQuery, repeatQuery);
	mainQuery.find({
		success: function(results) {
			res.success(results);
		},
		error: function(error) {
			// There was an error.
			mutil.cloudErrorFn(res)
		}
	});
}

exports.getTodayThingsByUserId = getTodayThingsByUserId;